Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows and bindings support #5

Merged
merged 33 commits into from
Jan 10, 2024
Merged

Conversation

novafacing
Copy link
Owner

Adds @tocklime's windows support and a few fixes and cleanups around it.

tocklime and others added 10 commits January 4, 2024 16:21
Add initial support for making windows delay-link library which hopefully
we will be able to link against.

qemu-plugins has win_link_hook which does the runtime link-up to the host
qemu.exe.

the tiny example compiles and runs for me now.

No way to access g_free on windows, so we instead leak memory at the moment.
@tocklime
Copy link
Contributor

tocklime commented Jan 7, 2024

I had a couple of ideas about the g_free problem, but haven't had a chance to try them yet.

  1. Try and resolve the g_free relative virtual address by inspecting the qemu binary, add that to the base address that qemu is loaded at and cast it to a fptr and use that. Not sure if I'll be able to do this, will require sufficient debug info in qemu.
  2. I think that on windows glib ends up just calling the 'normal' free function you get from Windows. If so, we might get away with calling that directly. If this worked, we would be relying on glib never changing internal details of his it mallocs and frees on windows.

@tocklime
Copy link
Contributor

tocklime commented Jan 8, 2024

Have had a quick play with this...

I had a couple of ideas about the g_free problem, but haven't had a chance to try them yet.

  1. Try and resolve the g_free relative virtual address by inspecting the qemu binary, add that to the base address that qemu is loaded at and cast it to a fptr and use that. Not sure if I'll be able to do this, will require sufficient debug info in qemu.

This is a non-starter, qemu as downloaded doesn't have debug symbols:
image

  1. I think that on windows glib ends up just calling the 'normal' free function you get from Windows. If so, we might get away with calling that directly. If this worked, we would be relying on glib never changing internal details of his it mallocs and frees on windows.
    This could work:
#[cfg(windows)]
unsafe fn g_free(mem: *mut c_void){
    //HACK: We would really like to call g_free in the qemu binary here
    //but we can't, because windows doesn't export symbols unless you explicitly export them
    //and qemu doesn't export g_free.

    //Instead we'll rely on glib only using stdlib.h's malloc/free and call it directly.
    //On glib docs, it says
    //> Since GLib 2.46 g_malloc() is hardcoded to always use the system malloc implementation.
    //So should be safe to call free ourselves.
    unsafe {
        if !mem.is_null() {
            libc::free(mem);
        }
    }
}

@novafacing
Copy link
Owner Author

Good enough for me, IMO better to make it work now than stress too much about it breaking in the future! Thanks for testing this out!

@novafacing
Copy link
Owner Author

novafacing commented Jan 8, 2024

I know combining "fix CI" and "add a feature" in one PR is bad practice, but luckily this repo has 5 stars so I think I can get away with it for now. I'll merge this once I can get CI to work, I just checked and there's enough space so something else weird is going on. The built image is 30.2GB, well under the available space.

@novafacing
Copy link
Owner Author

Getting there, Linux CI is working and what I'm trying to do for Windows CI is working locally :)

@novafacing novafacing merged commit c6817d6 into main Jan 10, 2024
2 checks passed
@novafacing
Copy link
Owner Author

Alrighty, it's not much but we are now testing Linux & Windows plugins in CI so that's cool! Thanks for doing the heavy lifting @tocklime!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants